package 开始的剑指offer8月.双指针;
// https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/
public class 剑指Offer18删除链表的节点0823 {

      public class ListNode {
          int val;
          ListNode next;
          ListNode(int x) { val = x; }
      }

    class Solution {
        public ListNode deleteNode(ListNode head, int val) {
            if(head.val == val) return head.next;
            ListNode pre = head, cur = head.next;
            while(cur != null && cur.val != val) {
                pre = cur;
                cur = cur.next;
            }
            if(cur != null) pre.next = cur.next;
            return head;
        }
    }


}
